<template>
    <div>     
        <h1 algin="center">登录页面</h1> 
        <table class="table table-bordered">
            
            <tr>
                <td>用户名</td>
                <td><input type="text" v-model="state.username" /></td>
            </tr>
            <tr>
                <td>密码</td>
                <td><input type="password" v-model="state.userpwd" /></td>
            </tr>
            <tr>
                <td></td>
                <td><input type="button" value="登录" @click="login" /></td>
            </tr>
        </table>
    </div>
</template>

<script setup lang="ts">
import {ref, reactive,toRefs} from "vue";
import axios from "axios";
import {useRouter,useRoute} from 'vue-router'
let router=useRouter();
let route=useRoute();

let data=reactive({
    state:{
         username:"",
         userpwd:""
    }
})
let {state}=toRefs(data);
const login=()=>{
    axios({
        url:"/api/Users/UserLogin",
        method:'get',
        params:{
            username:state.value.username,
            userpwd:state.value.userpwd
        }
    })
    .then(res=>{
        console.log(res.data.data);
       if(res.data.data==null)
        {
            alert("这不存在吧");
            router.push('/regist');
        }
        else 
        {
            alert("登录成功");
            return;
        }
    })
    .catch(err=>{
        console.log(err)
    })
}
</script>

<style>

</style>